///////////////////////////
// Common stuff

uniform vec4   InsideColor = vec4(0,0,0,1);
uniform vec4   BorderColor = vec4(1,1,1,1);
uniform float  BorderWidth = 26;
uniform float  PixelSize;

float Smooth(float ps, float a)
{
    //return smoothstep(-ps, +ps, a);
    //return (a < -ps*0.5) ? 0.0 : (a > +ps*0.5) ? 1.0 : (a+ps*0.5)/ps;
    return clamp(a/ps+0.5, 0.0, 1.0);
}

vec4 CalcColor(float d, float ysize, float cy)
{    
    d = -d; // Invert, so that d is the depth into the body
    float p = 0.5/ysize;
    if (d < BorderWidth*0.01) // Outside-fade
        return BorderColor;
    else // Inside fade
        return mix(InsideColor, vec4(InsideColor[0]*0.2,InsideColor[1]*0.2,InsideColor[2]*0.2,255), p*(ysize-cy));
}

//////////////////////////
uniform vec2 HalfSize;
uniform float Radius = 3;
uniform float CakeSize = 0.5; // 0 = no cake, 1 = all cake, 0.5=half cake etc

void main()
{
	vec4 color1 = vec4(1,1,1,1);
	vec4 color2 = vec4(0,0,1,1);
    const float pi = 3.141592653589793;
    vec2 tc = gl_TexCoord[0].st * 2.0 - 1.0;
    float dist = length(tc) * Radius;
    float t = atan(tc.y, tc.x); // In [-pi, +pi]
    float cakeSize = CakeSize * pi;
    gl_FragColor = mix(color1, color2, 1.0-Smooth(PixelSize / dist, abs(t)-cakeSize))
	// CalcColor(dist - Radius, HalfSize.y, gl_TexCoord[0].y);
    
    // gl_FragColor.rgb = ;
	gl_FragColor *= texture2D(tex, gl_TexCoord[0].xy);
}